package org.terrier.matching.models;

import org.terrier.utility.ApplicationSetup;

public class RLpdfL2 extends WeightingModel {
	private static final long serialVersionUID = 1L; 
	/*
	 * you can interface the result by tuning the following parameters
	 */
	/*
     * rayleigh pdf 
     */
    double rb = Double.parseDouble(ApplicationSetup.getProperty(
    		"distribution.parameter.0", "1"));
    double rayleighfirstpart = - 2 * Math.log(rb);

	public final String getInfo() {
		return "RLpdfL2_"+rb+"_"+c;
	}
	public double score(double tf, double docLength) {
		/*
		 * PL2 normalization
		 */
		double Linf = Idf.log(1 + c * averageDocumentLength / docLength);
		double tfn = tf * Linf;
		/*
		 * rayleigth
		 */	
		double LogRayleighValue = Math.log(tfn) - 
				(Math.pow(tfn, 2) * (1 / (2 * Math.pow(rb, 2)))) + rayleighfirstpart;
		double prob = Math.exp(LogRayleighValue);
		double inf1 = -(Math.log(prob)/Math.log(2));
		double inf2 = 1/(1 + tfn);
        return keyFrequency*inf1 * inf2;
	}
	public double score(//useless here
			double tf,
			double docLength,
			double n_t,
			double F_t,
			double keyFrequency) {
		/*
		 * PL2 normalization
		 */
		double Linf = Idf.log(1 + c * averageDocumentLength / docLength);
		double tfn = tf * Linf;
		/*
		 * rayleigth
		 */	
		double LogRayleighValue = Math.log(tfn) - 
				(Math.pow(tfn, 2) * (1 / (2 * Math.pow(rb, 2)))) + rayleighfirstpart;
		double prob = Math.exp(LogRayleighValue);
		double inf1 = -(Math.log(prob)/Math.log(2));
		double inf2 = 1/(1 + tfn);
        return keyFrequency*inf1 * inf2;
		}
}